Skip to main content

Tutorial: Statechart

Drafting and implementing a statechart

A statechart is a machine that switches from state to state at runtime. The states are linked by transitions, which each have a guard condition. Actions or methods can be called both in states and in transitions. When a guard condition gets the value TRUE (event), the transition will be activated. This executes the actions or methods that belong to the transition and then switches to the next state. Guard conditions are simply Boolean variables that reflect events or are an expression. Events are user input of a visualization/user interface, I/Os, time events, or system events. Another event that is often required is the completion event which occurs when the actions or methods of a state are completed.

You insert all required states in the statechart editor and implement the flow control. To do this, you code the guard conditions for the transitions by specifying a Boolean variable or an ST expression. You implement the actual functionality of the statechart in the actions and methods that are called in the states or during the transitions.

Therefore, the methods and actions assigned to a statechart contain the algorithms. This is how you implement the object-oriented class concept in the conventional way.

During the software design phase, you can already use the statechart editor as a design tool. For example, you can create a graphics file (BMP) from a statechart in order to add it to a specification or a design document.

  • Identify all the states that the machine will have.

  • Identify the possible state transitions from one state to another.

  • Identify the events that occur during the runtime of the machine and that trigger a state transition. Group the relevant events chronologically.

  • Identify the ENTRY, DO, and EXIT actions or methods to call during a state.

  • Identify actions or methods to call during transitions.

  • Define the behavior in the case of an error.